import service from "@/utils/AxiosJson";
import {StorageUtils} from "@/utils/StorageUtils";

export class ConfigUtils {
    static CONFIG = {
        baseUrl: '',
        websocketUrl: ''
    }

    private static readRequestConfig() {
        service({
            url: `/config.json`, // json文件地址
            method: 'GET',
        }).then((res: any) => {
            ConfigUtils.CONFIG = res;
        });
    }

    private static readCookieConfig() {
        StorageUtils.getStorage('request_api_address').then((data: string) => {
            ConfigUtils.CONFIG = JSON.parse(data) || {};
        })
    }

    public static readConfig() {
        ConfigUtils.readRequestConfig();
    }

    public static readText(fileUrl: string) {
        return service({
            url: fileUrl,
            method: 'GET',
            responseType: 'text'
        })
    }
}
